<template>
	<div>
		<questionitem v-if="questionTop.question_id"
		:question="questionTop"
		:type="nav.activeNav"
		:index=-1></questionitem>
		<questionitem v-for="(d,index) in questionData"
		:question="d"
		:type="nav.activeNav"
		:index="index"></questionitem>
	</div>
</template>
<script>
	import questionitem from '../QuestionItem.vue'
	import {getParameterByName, loadMore, myAlert} from '../../assets/js/utils.js'
	export default{
		name: 'board',
		data(){
			return{
				question:{
					type:3,
					data:[{
						question_id:'',
						question:'',
						question_describe:'',
						money:'',
						hot:'',
						browse_num:'',
						replynum:'',
						praisenum:''
					}]
				},
				hotlist:[],
				hotlistTop:{},
				money:{
					list:[],
					top:[],
					page:1
				},
				credit:{
					list:[],
					top:[],
					page:1
				},
				nav:''
			}
		},
		mounted(){
			// 拉取热度榜
			this.$http.post('',{
				name:'xwlt.pc.hotlist'
			}).then((response)=>{
				this.hotlist = response.body.data.hotlist;
			})
			// 拉取热度榜置顶
			this.$http.post('',{
				name:'xwlt.pc.toplist',
				type:'hot_top'
			}).then((response)=>{
				let hotlistTop = response.body.data.TopList;
				if(hotlistTop.question_id) this.hotlistTop = hotlistTop;
			})
			// 拉取悬赏榜
			// this.getMoneyData();
			// 拉取悬赏榜置顶
			this.$http.post('',{
				name:'xwlt.pc.toplist',
				type:'money_top'
			}).then((response)=>{
				let moneyTop = response.body.data.TopList;
				if(moneyTop) this.money.top = moneyTop;
			})
			// 拉取积分榜
			// this.getCreditData();
			// 拉取积分榜置顶
			this.$http.post('',{
				name:'xwlt.pc.toplist',
				type:'integral_top'
			}).then((response)=>{
				let creditTop = response.body.data.TopList;
				if(creditTop) this.credit.top = creditTop;
			})
		},
		methods:{
			getMoneyData(){
				this.$http.post('',{
					name:'xwlt.pc.MoneyRList',
					types:'money',
					page:this.money.page
				}).then((response)=>{
					let lists = response.body.data.MoneyRList;
					if(!lists.length) {
						loadMore.loadAll = true;
						loadMore.close();
					}
					this.money.list = this.money.list.concat(lists);
					this.money.page++;
					loadMore.loading = false;
				})
			},
			getCreditData(){
				this.$http.post('',{
					name:'xwlt.pc.MoneyRList',
					types:'integral',
					page:this.credit.page
				}).then((response)=>{
					let lists = response.body.data.MoneyRList;
					if(!lists.length) myAlert.small('全部加载完啦！');
					this.credit.list = this.credit.list.concat(lists);
					this.credit.page++;
					loadMore.loading = false;
				})
			}
		},
		computed:{
			questionData(){
				let questionData;
				switch(this.nav){
					case 0:
						questionData = this.hotlist;
						break;
					case 1:
						questionData = this.money.list;
						break;
					case 2:
						questionData = this.credit.list;
						break;
					default:
						questionData = [];
						return;
				}
				return questionData;
			},
			questionTop(){
				let questionTop;
				switch(this.nav){
					case 0:
						questionTop = this.hotlistTop;
						break;
					case 1:
						questionTop = this.money.top;
						break;
					case 2:
						questionTop = this.credit.top;
						break;
					default:
						questionTop = {};
						break;
				}
				return questionTop;
			}
		},
		watch:{
			currentNav(activeNav){
				this.nav = activeNav;
				loadMore.loading = true;
				this.money.list = this.credit.list = [];
				this.money.page = this.credit.page = 1;
				// 点击赏金榜
				if(activeNav===1){
					loadMore.close();
					loadMore.config.cb = this.getMoneyData;
					this.getMoneyData();
					loadMore.open();
				}
				// 点击积分榜
				else if(activeNav===2){
					loadMore.close();
					loadMore.config.cb = this.getCreditData;
					this.getCreditData();
					loadMore.open();
				}
			}
		},
		props:['currentNav'],
		components:{ questionitem }
	}
</script>
<style lang='less' scoped>
	@baseColor: #ffe857;
	@subColor: #f9c13a;
</style>